import { ref, Ref, onMounted } from 'vue'

const useMount = (offset: Ref<number>, selector: Ref<string>) => {
  const ele = ref<HTMLElement>()
  const isShow = ref<boolean>()
  isShow.value = offset.value === 0
  onMounted(() => {
    ele.value = document.querySelector(selector.value) as HTMLElement
    if (offset.value > 0 && ele.value) {
      ele.value.onscroll = () => {
        isShow.value = (ele.value as Element).scrollTop >= offset.value
      }
    }
  })

  return {
    ele,
    isShow
  }
}

export default useMount